package com.kakavr.staff.service;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang3.math.NumberUtils;
import org.joda.time.DateTime;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.kakavr.base.exception.ValidateParamException;
import com.kakavr.base.service.BaseService;
import com.kakavr.page.Pagination;
import com.kakavr.page.constant.PaginationConstant;
import com.kakavr.result.constant.MsgConstants;
import com.kakavr.staff.dao.IStaffAdminDao;

@Service
public class StaffAdminService extends BaseService implements
		IStaffAdminService {
	@Resource
	private IStaffAdminDao staffAdminDao;

	@Override
	public void addStaff(Map<String, Object> map) {
		if (staffAdminDao.selectStaffCountByUserName(map) > 0) {
			throw new ValidateParamException(MsgConstants.MSG_CODE_1003,
					MsgConstants.MSG_CONTENT_1003, "用户名");
		}
		map.put("createtime", DateTime.now().toDate());
		staffAdminDao.insertStaff(map);
	}

	@Override
	public Pagination<Map<String, Object>> selectStaffByPage(
			Map<String, Object> map) {
		PageHelper.startPage(NumberUtils.toInt((String) map.get(PaginationConstant.PAGE_NO_NAME)),
				NumberUtils.toInt((String) map.get(PaginationConstant.PAGE_SIZE_NAME)));
		return new Pagination<Map<String,Object>>(staffAdminDao.selectStaffByPage(map));
	}

	@Override
	public void updateStaff(Map<String, Object> map) {
		staffAdminDao.updateStaff(map);
	}

	@Override
	public List<Map<String, Object>> selectPartnerList() {
		return staffAdminDao.selectPartnerList();
	}

	@Override
	public void deleteStaff(Map<String, Object> map) {
		staffAdminDao.deleteStaff(map);
	}

}
